﻿using System;
using System.Collections.Generic;
using PrearrangedChaos.AgileZen.Service.Model;
using PrearrangedChaos.AgileZen.Service.Rest;

namespace PrearrangedChaos.AgileZen.Service
{
    internal class ZenStoryCollection<TCollection> : ZenResourceCollection<TCollection, IStory>, IZenStoryEnumerable
        where TCollection : class, IPagingResponse<IStory>
    {
        public IZenStoryEnumerable WithDetails
        {
            get
            {
                AddEnrichment("details");
                return this;
            }
        }

        public IZenStoryEnumerable WithMetrics
        {
            get
            {
                AddEnrichment("metrics");
                return this;
            }
        }

        public IZenStoryEnumerable WithComments
        {
            get
            {
                AddEnrichment("comments");
                return this;
            }
        }

        public IZenStoryEnumerable WithMilestones
        {
            get
            {
                AddEnrichment("milestones");
                return this;
            }
        }

        public IZenStoryEnumerable WithSteps
        {
            get
            {
                AddEnrichment("steps");
                return this;
            }
        }

        public IZenStoryEnumerable WithTasks
        {
            get
            {
                AddEnrichment("tasks");
                return this;
            }
        }

        public IZenStoryEnumerable WithTags
        {
            get
            {
                AddEnrichment("tags");
                return this;
            }
        }

        public ZenStoryCollection(string apiKey, int pageSize)
            : base(apiKey, RestArguments.Story(pageSize: pageSize))
        {
        }

        public ZenStoryCollection(string apiKey, int pageSize, int projectId)
            : base(apiKey, RestArguments.Story(projectId, pageSize: pageSize))
        {
        }

        public ZenStoryCollection(string apiKey, int pageSize, int projectId, int tagId)
            : base(apiKey, RestArguments.Story(projectId, tagId, pageSize: pageSize))
        {
        }

        public ZenStoryCollection(string apiKey, int pageSize, int projectId, string tag)
            : base(apiKey, RestArguments.Story(projectId, tag: tag, pageSize: pageSize))
        {
        }

        public IZenResourceEnumerable<IStory> Filter(Func<IStoryFilter, ZenFilter> filter)
        {
            SetFilter<StoryFilter>(filter);
            return this;
        }
    }
}